package com.luo.advice;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.io.IOException;
import java.sql.SQLException;

//全局式管理异常
//@RestControllerAdvice
public class SystemExceptionAdvice {
    //异常处理方式
    @ExceptionHandler(NumberFormatException.class)
    public String checkNumberFormatException(Exception e){
        //首先添加一个日志记录，保存到服务器
        e.printStackTrace();
        return "NumberFormatException请输入全数字";
    }
/**1212121*/
    @ExceptionHandler(ClassCastException.class)
    public String checkClassCastException(){
        return "ClassCastException类型转换异常";
    }

    @ExceptionHandler(ArrayIndexOutOfBoundsException.class)
    public String checkArrayIndexOutOfBoundsException(){
        return "ArrayIndexOutOfBoundsException数组下标超界";
    }

    @ExceptionHandler(NullPointerException.class)
    public String checkNullPointerException(){
        return "NullPointerException空指针异常";
    }

    @ExceptionHandler(SQLException.class)
    public String checkSQLException(){
        return "SQLException数据库异常";
    }

    @ExceptionHandler(IOException.class)
    public String checkIOException(){
        return "IOException IO流异常";
    }

}
